import { defineStore } from 'pinia'
import { Names } from './store-name'
// import { Local } from '@/utils/storage'

export const useLayoutConfigStore = defineStore(Names.LayoutConfig, {
  state: (): LayoutConfigState => {
    return {
      isCollapse: false,
      globalTitle: '航顺物料管理系统',
      isFullscreen: false, // 全屏
      isDrak: false, //是否暗黑主题
      tabTags: [{
        path: '/home',
        meta: {
          title: "首页",
        },
      }],
      currentMenu: null,
    }
  },
  getters: {

  },
  actions: {
    // updateState(state: LayoutConfigState) {
    //   // 讲传递的对象属性更新到state状态中
    //   this.$patch(state)
    // },
    selectMenu(tag: any) {
      if (tag.name === 'Home') {
        this.currentMenu = null
      } else {
        let index = this.tabTags.findIndex((item: any) => item.name === tag.name)
        index === -1 ? this.tabTags.push(tag) : ''
      }
    },
    updateTags(tag: any) {
      let index = this.tabTags.findIndex((item: any) => item.name === tag.name)
      this.tabTags.splice(index, 1)
    }
  }
})

// nextTick(() => {
//   const layoutConfig = useLayoutConfigStore()
//   // 监听状态变化
//   layoutConfig.$subscribe((_mutation, state) => {
//     // console.log('mutation, state', mutation, state);
//     // 保存到本地
//     Local.set('layoutConfig', state)
//   })
// })